package com.yien.springstudy.service.impl;

import com.yien.springstudy.service.BlockQueueService;

import java.util.concurrent.LinkedBlockingQueue;

/**
 * @author Miaoxiong Fan
 * @since version
 */

public class BlockQueueServiceImpl implements BlockQueueService {

    public static void main(String[] args) throws InterruptedException {
        BlockQueueService  blockQueueService = new BlockQueueServiceImpl();
        blockQueueService.createLinkedBlockQueue();
    }

    @Override
    public void createLinkedBlockQueue() throws InterruptedException {
        LinkedBlockingQueue<Integer> queue = new LinkedBlockingQueue<>();
        for (int i = 0; i < 10; i++) {
            queue.put(Integer.valueOf(i));
        }

        while (queue.size() > 0) {
            System.out.println(queue.take());
        }
        while (!queue.isEmpty()) {
            System.out.println(queue.take());
        }

    }
}
